package com.liuqi.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liuqi.project.common.ErrorCode;
import com.liuqi.project.common.model.entity.UserInterfaceInfo;
import com.liuqi.project.exception.BusinessException;
import com.liuqi.project.mapper.UserInterfaceInfoMapper;
import com.liuqi.project.service.UserInterfaceInfoService;
import org.springframework.stereotype.Service;

/**
 * @author liuqi
 * @description 针对表【user_interface_info(用户调用接口关系表)】的数据库操作Service实现
 * @createDate 2023-04-06 11:57:24
 */
@Service
public class UserInterfaceInfoServiceImpl extends ServiceImpl<UserInterfaceInfoMapper, UserInterfaceInfo>
        implements UserInterfaceInfoService {

    @Override
    public void validUserInterfaceInfo(UserInterfaceInfo userInterfaceInfo, boolean add) {
        if (userInterfaceInfo == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"用户接口信息为空");
        }
        // 创建时，所有参数必须非空
        if (add) {
            if (userInterfaceInfo.getInterfaceInfoId()<=0||userInterfaceInfo.getUserId()<=0) {
                throw new BusinessException(ErrorCode.PARAMS_ERROR,"接口或者用户不存在");
            }
            if (userInterfaceInfo.getLeftNum()<0) {
                throw new BusinessException(ErrorCode.PARAMS_ERROR, "剩余次数不能小于0");
            }
        }
    }

}




